<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
Class Login_m extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->load->database();
    }
    function select_mg()
    {
        $this->db->select('id_mg');
        $this->db->from('manager');
        $query=$this->db->get();
        return $query;
    }
    function login_admin($id_ad,$password)
    {
        $this->db->select('id_ad','password');
        $this->db->from('admin');
        $this->db->where('id_ad',$id_ad);
        $this->db->where('password',md5($password));
        $this->db->limit(1);
        $query_sm=$this->db->get();
        if($query_sm->num_rows()==1)
        {
            return $query_sm->result();
        }
        else 
        {
            return FALSE;
        }
    }

    function login_manager($id_mg,$password)
    {
        $this->db->select('*');
        $this->db->from('manager');
        $this->db->where('id_mg',$id_mg);
        $this->db->where('password',md5($password));
        $this->db->limit(1);
        $query_un=$this->db->get();
        if($query_un->num_rows()==1)
        {
            return $query_un->result();
        }
        else 
        {
            return FALSE;
        }
    }

    function login_examiner($id_ex,$password)
    {
        $this->db->select('*');
        $this->db->from('examiner');
        $this->db->where('id_ex',$id_ex);
        $this->db->where('password',$password);
        $this->db->limit(1);
        $query_answer=$this->db->get();
        if($query_answer->num_rows()==1)
        {
            return $query_answer->result();
        }
        else 
        {
            return FALSE;
        }
    }
    function login_examiner1($id_ex,$password,$manager)
    {
        $this->db->select('*');
        $this->db->from('examiner');
        $this->db->where('id_ex',$id_ex);
        $this->db->where('password',$password);
        $this->db->where('id_mg',$manager);
        $this->db->limit(1);
        $query_answer=$this->db->get();
        if($query_answer->num_rows()==1)
        {
            return $query_answer->result();
        }
        else 
        {
            return FALSE;
        }
    }
     function login_maker($id_mk,$password)
    {
        $this->db->select('id_mk','password');
        $this->db->from('maker');
        $this->db->where('id_mk',$id_mk);
        $this->db->where('password',$password);
        $this->db->limit(1);
        $query_answer=$this->db->get();
        if($query_answer->num_rows()==1)
        {
            return $query_answer->result();
        }
        else 
        {
            return FALSE;
        }
    }
     function login_maker1($id_mk,$password,$manager)
    {
        $this->db->select('*');
        $this->db->from('maker');
        $this->db->where('id_mk',$id_mk);
        $this->db->where('password',md5($password));
        $this->db->where('id_mg',$manager);
        $this->db->limit(1);
        $query_answer=$this->db->get();
        if($query_answer->num_rows()==1)
        {
            return $query_answer->result();
        }
        else 
        {
            return FALSE;
        }
    }
    function login_tester($id_te, $password,$testtitle)
    {
       $this->db->select('id_te','password');
        $this->db->from('tester');
        $this->db->where('id_te',$id_te);
        $this->db->where('password',md5($password));
        $this->db->where('testtitle',$testtitle);
        $this->db->limit(1);
        $query_answer=$this->db->get();
        if($query_answer->num_rows()==1)
        {
            return $query_answer->result();
        }
        else 
        {
            return FALSE;
        } 
    }
    function update_online_ad($id,$flag)
    {
        $update_onlineflag=array(
            'isonline'=>$flag

        );
        $this->db->update('admin',$update_onlineflag,array('id_ad'=>$id));
    }
    function update_online_mg($id,$flag)
    {
        $update_onlineflag=array(
            'isonline'=>$flag

        );
        $this->db->update('manager',$update_onlineflag,array('id_mg'=>$id));
    }
    function update_online_ex($id,$flag)
    {
        $update_onlineflag=array(
            'isonline'=>$flag

        );
        $this->db->update('examiner',$update_onlineflag,array('id_ex'=>$id));
    }
    function update_online_ex1($id,$manager,$flag)
    {
        $update_onlineflag=array(
            'isonline'=>$flag

        );
        $this->db->update('examiner',$update_onlineflag,array('id_ex'=>$id,'id_mg'=>$manager));
    }
    function update_online_mk($id,$flag)
    {
        $update_onlineflag=array(
            'isonline'=>$flag

        );
        $this->db->update('maker',$update_onlineflag,array('id_mk'=>$id));
    }
    function update_online_mk1($id,$manager,$flag)
    {
        $update_onlineflag=array(
            'isonline'=>$flag

        );
        $this->db->update('maker',$update_onlineflag,array('id_mk'=>$id,'id_mg'=>$manager));
    }
    function update_online_te($id,$testtitle,$flag)
    {
        $update_onlineflag=array(
            'isonline'=>$flag

        );
        $this->db->update('tester',$update_onlineflag,array('id_te'=>$id,'testtitle'=>$testtitle));
    }
    function select_online_flag_ad($id)
    {
        $this->db->select('*');
        $this->db->from('admin');
        $this->db->where('id_ad',$id);
        $this->db->where('isonline',1);
        $query=$this->db->get();
        return $query;
    }
    function select_online_flag_mg($id)
    {
        $this->db->select('*');
        $this->db->from('manager');
        $this->db->where('id_mg',$id);
        $this->db->where('isonline',1);
        $query=$this->db->get();
        return $query;
    }
    function select_online_flag_ex($id)
    {
        $this->db->select('*');
        $this->db->from('examiner');
        $this->db->where('id_ex',$id);
        $this->db->where('isonline',1);
        $query=$this->db->get();
        return $query;
    }
    function select_online_flag_ex1($id,$manager)
    {
        $this->db->select('*');
        $this->db->from('examiner');
        $this->db->where('id_ex',$id);
        $this->db->where('id_mg',$manager);
        $this->db->where('isonline',1);
        $query=$this->db->get();
        return $query;
    }
    function select_online_flag_mk($id)
    {
        $this->db->select('*');
        $this->db->from('maker');
        $this->db->where('id_mk',$id);
        $this->db->where('isonline',1);
        $query=$this->db->get();
        return $query;
    }
    function select_online_flag_mk1($id,$manager)
    {
        $this->db->select('*');
        $this->db->from('maker');
        $this->db->where('id_mk',$id);
        $this->db->where('id_mg',$manager);
        $this->db->where('isonline',1);
        $query=$this->db->get();
        return $query;
    }
    function select_online_flag_te($id,$testtitle)
    {
        $this->db->select('*');
        $this->db->from('tester');
        $this->db->where('id_te',$id);
        $this->db->where('testtitle',$testtitle);
        $this->db->where('isonline',1);
        $query=$this->db->get();
        return $query;
    }
    function select_offline_flag_te($id,$testtitle)
    {
        $this->db->select('*');
        $this->db->from('tester');
        $this->db->where('id_te',$id);
        $this->db->where('testtitle',$testtitle);
        $this->db->where('isoffline',1);
        $query=$this->db->get();
        return $query;
    }
    function update_offline_te($id,$testtitle,$flag)
    {
        $update_onlineflag=array(
            'isoffline'=>$flag

        );
        $this->db->update('tester',$update_onlineflag,array('id_te'=>$id,'testtitle'=>$testtitle));
    }

}
?>
